<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>组件切换</title>
    <script src="../vue.js"></script>
  </head>
  <body>
    <div id="app">
      <a href="#" @click.prevent="flag=true">登录</a>
      <a href="#" @click.prevent="flag=false">注册</a>
      <login v-if="flag"></login>
      <register v-else></register>
    </div>

    <template id="temp1">
      <div>登陆界面</div>
    </template>
    <template id="temp2">
      <div>注册界面</div>
    </template>
    <script>
      Vue.component("login", {
        template: "#temp1",
      });
      Vue.component("register", {
        template: "#temp2",
      });
      new Vue({
        el: "#app",
        data: { flag: true },
      });
    </script>
    <hr />
    <div id="app2">
      <a href="#" @click.prevent="comName='login'">登录</a>
      <a href="#" @click.prevent="comName='register'">注册</a>
      <component :is="comName"></component>
    </div>
    <template id="template1">
      <div>登陆界面</div>
    </template>
    <template id="template2">
      <div>注册界面</div>
    </template>
    <script>
      Vue.component("login", {
        template: "#template1",
      });
      Vue.component("register", {
        template: "#template2",
      });

      new Vue({
        el: "#app2",
        data: {
          comName: "",
        },
      });
    </script>
  </body>
</html>
